<#escape  x as x?xml>
<?xml version ="1.0" ?>
<category id="${entity.id}">
    <title>${entity.title}</title>
    <fullTitle>${stripCategory(entity.fullTitle)}</fullTitle>
    <description>${entity.description!}</description>
    <bigBoxUrl>${entity.bigBoxUrl!}</bigBoxUrl>
    <bannerAdUrl>${entity.bannerAdUrl!}</bannerAdUrl>
    <bannerAdUrlForIPhone>${entity.bannerAdUrlForIPhone!}</bannerAdUrlForIPhone>
    <thumbnailUrl>${entity.thumbnailUrl!}</thumbnailUrl>
    <#if entity.sortField! == "title">
    	<#assign sortField = "title">
    <#else>
    	<#assign sortField = "airDate">
    </#if>
    <sortField>${sortField!}</sortField>
    <sortOrder>${entity.sortOrder!}</sortOrder>
    <groupLevel>${entity.groupLevel!}</groupLevel>
    <groupOrder>${entity.groupOrder!}</groupOrder>
    <medias>
    	<#assign nowTime = .now?long>
    	<#if entity.sortOrder! == "Ascending">
		    <#list entity.medias?sort_by(sortField) as media>
		    <#if (!(media.unapprovedDate??) || nowTime <= media.unapprovedDate?long) && media.approved>
		        <media id="${media.id}">
		            <title>${media.title}</title>
		            <mobileId>${media.mobileId}</mobileId>
		            <showName>${media.show!}</showName>
		            <thumbnailUrl>${media.thumbnailUrl!}</thumbnailUrl>
		            <airDate>${media.airDate!}</airDate>
		            <genre>${media.genre!}</genre>
		            <expiryDate>${media.mobileExpiryDate!}</expiryDate>
		            <unapprovedDate>${media.unapprovedDate!}</unapprovedDate>
		            <length>${media.length} </length>
		            <account>${media.account!}</account>
		            <adCategory>${media.adCategory!}</adCategory>
		            <description>${media.description!}</description>
		            <availableDate>${media.availableDate!}</availableDate>
		            <geoRestriction>
		            	<relationship>${media.excludeCountries?string("deny", "allow")!}</relationship>
		            	<countries>${media.countries!}</countries>
		            </geoRestriction>
		            <categories>
		                <#list media.categories as category>
		                    <category>
		                         <fullTitle>${category.fullTitle}</fullTitle>
		                    </category>
		                </#list>
		            </categories>
		            <seasonNumber>${media.seasonNumber!}</seasonNumber>
		            <episodeNumber>${media.episodeNumber!}</episodeNumber>
		            <audioVideo>${media.audioVideo!}</audioVideo>
		            <approved>${media.approved?string("true", "false")}</approved>
		        </media>
		        </#if>
		    </#list>
		<#else>
		    <#list entity.medias?sort_by(sortField)?reverse as media>
		    <#if (!(media.unapprovedDate??) || nowTime <= media.unapprovedDate?long) && media.approved>
		        <media id="${media.id}">
		            <title>${media.title}</title>
		            <mobileId>${media.mobileId}</mobileId>
		            <showName>${media.show!}</showName>
		            <thumbnailUrl>${media.thumbnailUrl!}</thumbnailUrl>
		            <airDate>${media.airDate!}</airDate>
		            <genre>${media.genre!}</genre>
		            <expiryDate>${media.mobileExpiryDate!}</expiryDate>
		            <unapprovedDate>${media.unapprovedDate!}</unapprovedDate>
		            <length>${media.length} </length>
		            <account>${media.account!}</account>
		            <adCategory>${media.adCategory!}</adCategory>
		            <description>${media.description!}</description>
		            <availableDate>${media.availableDate!}</availableDate>
		            <geoRestriction>
		            	<relationship>${media.excludeCountries?string("deny", "allow")!}</relationship>
		            	<countries>${media.countries!}</countries>
		            </geoRestriction>
		            <categories>
		                <#list media.categories as category>
		                	<#if category.fullTitle != "">
			                    <category>
			                         <fullTitle>${category.fullTitle}</fullTitle>
			                    </category>
		                    </#if>
		                </#list>
		            </categories>
		            <seasonNumber>${media.seasonNumber!}</seasonNumber>
		            <episodeNumber>${media.episodeNumber!}</episodeNumber>
		            <audioVideo>${media.audioVideo!}</audioVideo>
		            <approved>${media.approved?string("true", "false")}</approved>
		        </media>
		        </#if>
		    </#list>
    	</#if>
    </medias>
        <sponsors>
        <#list entity.sponsors as sponsor>
            <sponsor>
                <imageUrl>${sponsor.imageUrl!}</imageUrl>
                <url>${sponsor.url!}</url>
            </sponsor>
        </#list>
        </sponsors>
</category>
</#escape>

<#function stripCategory fullTitle>
	<#local ft = fullTitle>
    <#if fullTitle?starts_with("Shows/Shows")>
    	<#local ft = fullTitle?replace('Shows/Shows', 'Shows', 'f')>
    <#elseif fullTitle?starts_with("Radio/Shows")>
    	<#local ft = fullTitle?replace('Radio/Shows', 'Radio', 'f')>
    </#if>
    <#return ft>
</#function>
